package cn.yyx.ossservice;

import cn.yyx.common.R;
import cn.yyx.common.utils.RecognizeGeneral;
import cn.yyx.common.utils.RecognizeIdcard;
import cn.yyx.customerservice.OssUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/eduoss")
public class OssController {
    /**
     * 上传身份证并识别的方法
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("fileoss")
    public R uploadOssFile(@RequestBody MultipartFile file) throws Exception {
        String filename = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
        String url = OssUtil.uploadObject2OSS(OssUtil.getOSSClient(), file, OssUtil.BUCKET_NAME, filename, OssUtil.FOLDER);
        return R.ok().data("url", url).data("info", RecognizeIdcard.Recognize(url));
    }
    @PostMapping("expenses/fileoss")
    public R euploadOssFile(@RequestBody MultipartFile file) throws Exception{
        String filename = UUID.randomUUID().toString().replaceAll("-","")+".jpg";
        String url = OssUtil.uploadObject2OSS(OssUtil.getOSSClient(), file, OssUtil.BUCKET_NAME, filename, OssUtil.FOLDER);
        Map<String,Object> map = RecognizeGeneral.getInfo(url);

        return R.ok().data(map);
    }
}
